package AIGUI;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyAIApp {
    public MyAIApp() {
        // 创建主窗口
        JFrame mainFrame = new JFrame("MyAI");
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainFrame.setSize(600, 400); // 调整窗口大小
        mainFrame.setLayout(new BorderLayout());

        // 自定义面板用于绘制背景图片
        JPanel backgroundPanel = new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                // 绘制背景图片
                ImageIcon icon = new ImageIcon("src/pic/006opV64ly1hokn0lhc81j32yo1o1qvc.jpg");
                Image image = icon.getImage();
                g.drawImage(image, 0, 0, getWidth(), getHeight(), this);
            }
        };
        backgroundPanel.setLayout(new BorderLayout());

        // 创建标题
        JLabel titleLabel = new JLabel("欢迎来到MyAI!", JLabel.CENTER);
        titleLabel.setFont(new Font("微软雅黑", Font.BOLD, 24));
        backgroundPanel.add(titleLabel, BorderLayout.NORTH);

        // 创建按钮面板
        JPanel buttonPanel = new JPanel();
        buttonPanel.setOpaque(false); // 使按钮面板透明
        buttonPanel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(10, 10, 10, 10); // 设置按钮间距

        // 创建按钮
        JButton chatButton = new JButton("AI智能对话");
        JButton text2ImageButton = new JButton("AI生成图片");
        JButton image2TextButton = new JButton("AI图生文");

        // 添加按钮到面板
        gbc.gridx = 0;
        gbc.gridy = 0;
        buttonPanel.add(chatButton, gbc);

        gbc.gridy = 1;
        buttonPanel.add(text2ImageButton, gbc);

        gbc.gridy = 2;
        buttonPanel.add(image2TextButton, gbc);

        backgroundPanel.add(buttonPanel, BorderLayout.CENTER);

        mainFrame.setContentPane(backgroundPanel); // 设置背景面板为主窗口的内容面板

        // 添加按钮点击事件监听器
        chatButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(() -> new TalkTOAI().createAndShowGUI());
            }
        });

        text2ImageButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(() -> new GPICGUI().createAndShowGUI());
            }
        });

        image2TextButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                SwingUtilities.invokeLater(() -> new UDSPICGUI().createAndShowGUI());
            }
        });
        // 设置窗口居中
        mainFrame.setLocationRelativeTo(null);
        // 显示主窗口
        mainFrame.setVisible(true);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(MyAIApp::new);
    }
}
